/*Author: Rony Lahav (ID:043489889)*/

import java.io.Serializable;


/**
 * This class represents one tuple in the DB that holds one peer's data
 */
public class DBTuple implements Serializable, Comparable<DBTuple>{
	private static final long serialVersionUID = -2487635685467654329L;

	private String peerID;
	private String peerIP;
	private String udpPort;
	private boolean isSN;
	private long lastConnectionTime;
	private String status;
	private boolean isMainSN;
	private String connectedThrough;

	public boolean IsMainSN(){
		return isMainSN;
	}
	
	public void setIsMainSN(boolean val){
		isMainSN=val;
	}
	
	public String ConnectedThrough(){
		return connectedThrough;
	}
	
	public void setConnectedThrough(String val){
		connectedThrough=val;
	}
	
	public boolean IsSN(){
		return isSN;
	}
	
	public void setIsSN(boolean val){
		isSN=val;
	}
	
	public String getConnectedThrough(){
		return connectedThrough;
	}
	
	public String getPeerID() {
		return peerID;
	}

	public void setPeerID(String peerID) {
		this.peerID = peerID;
		
	}

	public String getPeerIP() {
		return peerIP;
	}

	public void setPeerIP(String peerIP) {
		this.peerIP = peerIP;
	}

	public String getUdpPort() {
		return udpPort;
	}

	public void setUdpPort(String udpPort) {
		this.udpPort = udpPort;
	}

	public long getLastConnectionTime() {
		return lastConnectionTime;
	}

	public void setLastConnectionTime(long lastConnectionTime) {
		this.lastConnectionTime = lastConnectionTime;
	}

	public boolean getStatus() {
		return Integer.parseInt(status) == 1;
	}
	
	public String getStatusAsString() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getKey() {
		return peerIP+":"+udpPort;
	}
	
	//constructor
	public DBTuple(){
		isMainSN = false;
		connectedThrough = "0";
	}
	
	@Override
	public String toString() {

		String sb = 
			"Peer ID = " + peerID
		 +  "\nPeer IP = " + peerIP
		 + 	"\nUDP Port = " + udpPort
		 + 	"\nLast Connection Time = " + lastConnectionTime
		 + 	"\nStatus = " + status
		 +  "\nIsSN = " + isSN;

		return sb;
	}

	@Override
	//public int compareTo(Object arg0) {
	public int compareTo(DBTuple tuple) {
		// TODO Auto-generated method stub
		return this.peerID.compareTo(tuple.peerID);
	}
	
	public DBTuple clone(){
		DBTuple newTuple = new DBTuple();
		//newTuple.buffer = this.buffer;
		newTuple.peerIP = this.peerIP;
		newTuple.lastConnectionTime = this.lastConnectionTime;
		newTuple.peerID = this.peerID;
		newTuple.status = this.status;
		newTuple.udpPort = this.udpPort;
		newTuple.isSN = this.isSN;
		
		return newTuple;
	}

}
